package com.master5.grocerylist.credentials;

import static org.junit.Assert.*;

import java.net.URI;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;

import org.junit.Before;
import org.junit.Test;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;

public class CredentialsAlternativeTest {

	private WebResource service;
	
	@Before
	public void setUp() throws Exception {
		ClientConfig config = new DefaultClientConfig();
		Client client = Client.create(config);
		service = client.resource(getBaseURI());
	}

	@Test
	public void test() {
		String name = "yigit", password = "bekir";
		int id = 1;
		Credentials result = service.path("api").path("login").path("auth").path(name).path(password)
				.accept(MediaType.APPLICATION_JSON).get(Credentials.class);
		
		assertEquals(result.getUserName(), name);
		assertEquals(result.getPassword(), password);
		assertEquals(result.getUserId(), id);
	}
	
	private URI getBaseURI() {
		return UriBuilder.fromUri(
				"http://grocerylistserv.appspot.com").build();
	}

}
